<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>shellSort</title>
  </head>
  <body>
    <script>
      function shellSort(array) {
        let length = array.length,
          gap = Math.floor(length / 2);
        while (gap >= 1) {
          for (let i = gap; i < length; i++) {
            let tmp = array[i],
              j = i;
            while (array[j - gap] > tmp && j > gap - 1) {
              array[j] = array[j - gap];
              j -= gap;
            }
            array[j] = tmp;
          }
          gap = Math.floor(gap / 2);
        }
        return array;
      }
      let arr = [123, 14, 521, 8, 31, 943, 19, 56, 241];
      console.log(shellSort(arr));
    </script>
  </body>
</html>
